package com.udaos.modules.section.services;

import java.util.ArrayList;
import java.util.List;

import org.nutz.aop.interceptor.ioc.TransAop;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;

import com.udaos.common.base.Service;
import com.udaos.common.util.StringUtil;
import com.udaos.models.school.Ud_school_area;
import com.udaos.models.section.Ud_section_resource;

/**
 * @author mutaotao
 * @time 2017-03-28 16:22:06
 * 
 */
@IocBean(args = { "refer:dao" })
public class UdSectionResourceService extends Service<Ud_section_resource> {
	public UdSectionResourceService(Dao dao) {
		super(dao);
	}

	@Aop(TransAop.READ_COMMITTED)
	public void insertList(List<Ud_section_resource> crs) {
		dao().fastInsert(crs);
		
	}

	@Aop(TransAop.READ_COMMITTED)
	public void updateResource(String id, String resourceid) {
		dao().execute(Sqls.create("delete from ud_section_resource where section_id= @id").setParam("id", id));
		if(!Strings.isBlank(resourceid)){
			String []resourceids=resourceid.split(",");
        	List<Ud_section_resource> crs=new ArrayList<Ud_section_resource>();
        	for (int i = 0; i < resourceids.length; i++) {
        		Ud_section_resource sr=new Ud_section_resource();
        		sr.setResource_id(resourceids[i]);
        		sr.setSection_id(id);
        		crs.add(sr);
			}
        	dao().fastInsert(crs);
        }
	}

	@Aop(TransAop.READ_COMMITTED)
	public void deleteBySectionId(String id) {
		dao().execute(Sqls.create("delete from ud_section_resource where section_id= @id").setParam("id", id));
	}
	@Aop(TransAop.READ_COMMITTED)
	public void deleteByResourceId(String id) {
		dao().execute(Sqls.create("delete from ud_section_resource where _resource_id= @id").setParam("id", id));
	}
	
}